-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Chip] Add clickable
property
#11613
Conversation
...other | ||
} = this.props; | ||
|
||
const className = classNames( | ||
classes.root, | ||
{ [classes.clickable]: onClick }, | ||
{ [classes.clickable]: onClick || clickable}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clickable }
@@ -239,10 +240,15 @@ Chip.propTypes = { | |||
* @ignore | |||
*/ | |||
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | |||
/** | |||
* Boolean to determine if the chip should be clickable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the wording of other bool props. ('If true, ...')
clickable
prop
}; | ||
|
||
Chip.defaultProps = { | ||
component: 'div', | ||
clickable: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing comma, and clickable
goes before component
.
run |
You'll also need to run Oh, and update the typescript definition ( |
@mbrookes Hi, I am done with other comments, but not able to run yarn docs:api / npm run docs:api. I face an error "module not found 'deepmerge'". Even if I install deepmerge, I get further errors. Can you help me in this? |
Are you using yarn or npm? Did you run |
No idea, but since you have yarn, try running Failing that, I'll do it push to your repo. |
@mbrookes Wow. That worked. Hopefully its time for me to move to yarn from npm ;-). I guess PR is good right now. Please review it |
@@ -242,6 +248,7 @@ Chip.propTypes = { | |||
}; | |||
|
|||
Chip.defaultProps = { | |||
clickable: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the clickable
property have a higher priority than the onClick
detection logic?
Meaning, what's the output of <Chip clickable={false} onClick={() => ()} />
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviertassinari I feel clickable should have low priority than OnClick. The output of above will still be clickable as per the below code: { [classes.clickable]: onClick || clickable },
if onclick is present, it will be clickable at any cost. Only when onClick is not present, clickable comes into the picture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviertassinari This is only affecting the styling (and the description should perhaps reflect that), but requiring the prop to be set in order for a Chip with onClick to appear clickable seems counter-intuitive to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but requiring the prop to be set in order for a Chip with onClick to appear clickable seems counter-intuitive to me.
@mbrookes I was asking the question in a context where defaultProps.clickable = null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. So being able to set clickable={somethingFalse}
when a Chip has an onClick()
handler but other conditions mean that it won't act on the click?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliviertassinari I feel defaultProps.clickable = null also would work fine. still false makes better sense, as we have kept props type as boolean. Also, in terms of functionality, nothing changes in either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbrookes Couldn't understand your question clearly. But to explain, if we have 'onClick' hander, 'clickable' doesn't affect and the chip is always clickable. when 'onClick' is not present, then the value of 'clickable' determine if the chip is clickable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vilvaathibanpb I was just clarifying with @oliviertassinari if I understood correctly the benefit of defaultProps.clickable = null
combined with clickable having priority.
Let me rephrase it as a direct question: @oliviertassinari What do you see as the main benefit for null
as the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you see as the main benefit for null as the default?
The advantage is that it's allowing people to control the clickable state, but still, being able to rely on the onClick detection logic if they wish. But I'm fine either way. The current approach is simple too.
clickable
propclickable
property
/** | ||
* If `true`, the chip will be clickable. | ||
* By default, the chip will not be clickable. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming we keep the current logic, the wording needs to be something like:
"If true
, the chip will appear clickable, and will raise when pressed, even if the onClick
property is not defined. This can be used, for example, along with the component
property to indicate an anchor Chip is clickable."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And an example in the docs would be good...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbrookes Have changed the comments and added an example as well. Please let me know if any other changes are required
docs/src/pages/demos/chips/Chips.js
Outdated
@@ -30,6 +30,7 @@ function Chips(props) { | |||
return ( | |||
<div className={classes.root}> | |||
<Chip label="Basic Chip" className={classes.chip} /> | |||
<Chip label="Clickable without onClick Chip" clickable className={classes.chip} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbrookes Unless I'm missing something, by demo, the point was to showcase a link chip no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. For buttons we link to the page section id, so a link to '#chip' would do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. you also want me to add component 'a' ? or just adding a 'href="#chip"' will do? And what title will be suitable for it? "Link" or "Clickable without onClick chip (Link)".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever use case you're solving for, and as short a name as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbrookes I have added link to the Chip and also made the name as Clickable Link Chip. Please let me know if I have to make any more changes
docs/src/pages/demos/chips/Chips.js
Outdated
label="Clickable Link Chip" | ||
className={classes.chip} | ||
clickable | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you put this last in the list of Chips?
In terms of prop ordering, lets put the added props at the end for clarity:
<Chip
label="Clickable Link Chip"
className={classes.chip}
component="a"
href="#chip"
clickable
/>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbrookes Have rearranged the props. Any other suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you put this last in the list of Chips?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbrookes Sorry I just missed that. Have moved it to the last in the list of Chips. Thanks a lot for your patience as I make so many issues.
@mbrookes Please review and let me know if any further changes required. Hopefully, everything is done 👍 |
@vilvaathibanpb So far so good, but it looks like you still need to fix the underline? |
@mbrookes underline as in ? U dont need underline for a Link chip? |
@mbrookes and @oliviertassinari Ideally this text decoration should be none for chip in the root level right? Not just for clickable |
@mbrookes Can you check now, please? |
For some reason, the new chip link demo isn't keyboard accessible. |
@oliviertassinari Sure? Because I was able to access the chip with keyboard (Tab key). I use Mac - chrome 64 |
@oliviertassinari Sorry my bad. If you notice, even Basic chip is not accessible through keyboard. Only when onclick or onDelete is present, the chips are keyboard accessible |
@oliviertassinari Have made the chip accessible through the keyboard. Check now, please. |
This was my first Open source contribution and i learnt so much about detailing and looking for various checks. Thank you so much for your patience @mbrookes and @oliviertassinari |
@vilvaathibanpb Thanks for seeing this through. I appreciate it was a lot of work for a small change, but hopefully that gives some insight into how much care has gone into the rest of the library. (Which is not to say it's perfect by any means, but we try our best! 😅) |
This would be much better if having |
@mbrookes Should we consider @zachrickards request? |
@vilvaathibanpb This sounds like a valid request to me! |
@zachrickards Please open an issue for it so it doesn't get lost. Better still, would you like to work on it? |
@oliviertassinari and @mbrookes I can pick it up |
Have added a new prop for the Chip - 'clickable' which takes a boolean as input and makes the Chip clickable irrespective of the component type
Closes #11502